<template>
	<view class="j-me-info">
		<view class="item-container" v-if="goodsList.length">
			<view class="thumb-box" v-for="(item1, index1) in goodsList" :key="index1" >
				<!-- @click="toGoodsList(item1)" -->
				<view class="thu" @click="getId(item1)">
					<view
						:class="[shoppingCartIds.length && shoppingCartIds.includes(item1.shoppingCartId) ? 'item-menu-name-gx item-menu-name-gx-xz' : 'item-menu-name-gx']   ">
						<image style="width: 10.39px;height: 6.82px;" src="../../../../static/image/gx.png" mode="">
						</image>
					</view>
				</view>

				<image class="item-menu-image" :src="JSON.parse(item1.goodsImages)[0]" mode=""></image>
				<view class="item-menu-name">
					<view class="item-menu-name-title">
						{{item1.goodsName}}
					</view>
					<view class="item-menu-name-bq">
						新款特价
					</view>
					<view class="item-menu-name-ys">
						月售29
					</view>
					<view class="item-menu-name-jiage">
						<view class="item-menu-name-jg">
							{{item1.price}}
						</view>
						<view class="item-menu-name-jia" @click="addShop(item1,1)">
							+
						</view>
						<view class="item-menu-name-jia">
							{{item1.goodsNum}}
						</view>
						<view class="item-menu-name-jia" style="margin-right: 0px;" @click="addShop(item1,2)">
							-
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="jsCon">
			<view class="shdz" @click="goshopping" v-if="goodsList.length">
				去结算
			</view>
		</view>
		
		<view class="noList" v-if="!goodsList.length">
			<view class="noListoneTitle">
				购物车空空如也
			</view>
			<view class="noListTTitle">
				快选束鲜花送给自己吧
			</view>
			<view class="noListBtn" @click="todiand">
				去逛逛
			</view>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userInfo: {},
				goodsList: [],
				params: {
					hidPic: '',
					nickName: '',
					birthday: '',
					sex: '',
					hbUrl: '',
					hbImg: ''
				},
				shoppingCartIds: [],
				shoppingCartIdObj: []
			};
		},
		onShow() {
			// 获取当前登录用户的基本信息
			this.postGetUserInfo();
		},
		onLoad() {
			// this.$u.api.postShoppingFindList.then(res => {
			// 	console.log(res, "123")
			// })
		},
		methods: {
			todiand(){
				uni.reLaunch({
					url: '/pages/category/category'
				})
				// uni.navigateTo({
				// 	url: '../../..'
				// });
			},
			addShop(item, num) {
				if (item.goodsNum == 1 && num == 2) {
					let params = {
						shoppingCartIds: item.shoppingCartId
					}
					this.$u.api
						.postremoveShoppingCart(params)
						.then(res => {
							console.log(res, "11111")
							this.postGetUserInfo()
						})
				} else {
					let params = {
						type: num,
						shoppingCartId: item.shoppingCartId
					}
					this.$u.api
						.postupdateShoppingCart(params)
						.then(res => {
							console.log(res, "222")
							this.postGetUserInfo()
						})
				}

			},
			//获取购物车勾选id
			getId(item) {
				console.log(item, "item")
				if (this.shoppingCartIds.includes(item.shoppingCartId)) {
					this.shoppingCartIds.splice(this.shoppingCartIds.indexOf(item.shoppingCartId), 1)
					this.shoppingCartIdObj.splice(this.shoppingCartIds.indexOf(item.shoppingCartId), 1)
				} else {
					this.shoppingCartIds.push(item.shoppingCartId)
					this.shoppingCartIdObj.push(item)
				}
				console.log(this.shoppingCartIdObj, "item")
			},
			goshopping() {
				if (!this.shoppingCartIdObj.length) {
					this.$refs.uToast.show({
						title: '请勾选要买的东西'
					})
					return false;
				}
				this.$u.api
					.postIsLogin()
					.then(res => {
						// console.log(res,"resresres")
						console.log(this.shoppingCartIdObj,"re111sresres")
						// this.orderParams.orderType = uni.getStorageSync('orderType')
						uni.reLaunch({
							url:'/pages/index/confirm-order/shopingconfirm-order?orderParams=' + encodeURIComponent( JSON.stringify(this
								.shoppingCartIdObj))
							// url: '../../../index/confirm-order/shopingconfirm-order?orderParams=' + JSON.stringify(this
							// 	.shoppingCartIdObj)
						});
					})
				// let params = {
					
				// }
				// this.$u.api
				// 	.postshoppingCartBuyMallGoods()
				// 	.then(res => {
				// 		uni.navigateTo({
				// 			url: '../../../index/confirm-order/shopingconfirm-order'
				// 		});
				// 	})
				
				
			},
			// 获取当前登录用户的基本信息
			postGetUserInfo() {
				this.$u.api
					.postShoppingFindList()
					.then(res => {
						this.goodsList = res.data
						console.log(this.goodsList, "1");
						// this.userInfo = res.data;
					})
					.catch(err => {
						console.log(err);
						if (err.status == 401) {
							this.userInfo = {};
						}
					});
			},
			// 打开裁剪头像的页面
			chooseAvatar() {
				// 此为uView的跳转方法，详见"文档-JS"部分，也可以用uni的uni.navigateTo
				this.$u.route({
					// 关于此路径，请见下方"注意事项"
					url: '/node_modules/uview-ui/components/u-avatar-cropper/u-avatar-cropper',
					// 内部已设置以下默认参数值，可不传这些参数
					params: {
						// 输出图片宽度，高等于宽，单位px
						destWidth: 200,
						// 裁剪框宽度，高等于宽，单位px
						rectWidth: 200,
						// 输出的图片类型，如果'png'类型发现裁剪的图片太大，改成"jpg"即可
						fileType: 'jpg'
					}
				});
			},
			// 跳转编辑昵称页面
			toEditNickname() {
				uni.navigateTo({
					url: './me-edit-nickname'
				});
			},
			// 跳转编辑虚拟币账户页面
			toEditHbAccount() {
				uni.navigateTo({
					url: './me-edit-hb-account'
				});
			},
			// 跳转编辑虚拟币账户图片页面
			toEditHbImage() {
				uni.navigateTo({
					url: './me-edit-hb-image?path=' + this.userInfo.hbImg
				});
			}
		}
	};
</script>

<style>
	page {
		background-color: #f3f3f3;
	}
</style>
<style scoped lang="scss">
	.noList {
		width: 94%;
		height: 20vh;
		background: #fff;
		text-align: center;
		margin: 1vh auto;
		padding-top: 4vh;

		.noListoneTitle {
			font-family: PingFang SC;
			font-size: 16px;
			font-weight: bold;
			line-height: 22px;
			text-align: center;
			letter-spacing: 0px;
			color: #333333;
		}

		.noListTTitle {
			font-family: PingFang SC;
			font-size: 14px;
			font-weight: normal;
			line-height: 20px;
			text-align: center;
			letter-spacing: 0px;
			color: #999999;
			margin-top: 1vh;
		}

		.noListBtn {
			width: 89px;
			height: 35px;
			border-radius: 17.5px;
			opacity: 1;
			box-sizing: border-box;
			border: 1px solid #055A61;
			line-height: 35px;
			margin: 2vh auto;
			font-size: 14px;
		}
	}
.jsCon{
	position: fixed;
	bottom: 0;
	width: 100vw;
	height: 10vh;
	background: #fff;
	.shdz {
		width: 80vw;
		height: 5vh;
		margin: 2.5vh auto;
		text-align: center;
		background: #003B40;
		color: #fff;
		left: 10vw;
		line-height: 5vh;
		border-radius: 30px;
	}
}
	

	.thu {
		width: 120rpx;
		height: 201rpx;
		display: inline-block;
		vertical-align: top;
		margin-left: 2vw;
		text-align: center;
		line-height: 200rpx;
	}

	.item-menu-name-gx {
		// float: right;
		width: 20px;
		height: 20px;
		background: #fff;
		color: #fff;
		display: inline-block;
		text-align: center;
		line-height: 15px;
		border-radius: 50%;
		border: 1px solid #ccc;
		// margin-top: -10rpx;

	}

	.item-menu-name-gx-xz {
		background: #003B40;
	}

	.j-me-info {
		width: 100vw;
		// height: 98vh;
		padding-bottom: 10vh;
		background: #F8F9FA;
	}

	.u-wrap {
		height: calc(100vh);
		/* #ifdef H5 */
		height: calc(100vh - var(--window-top));
		/* #endif */
		display: flex;
		flex-direction: column;
	}

	.u-search-box {
		padding: 18rpx 30rpx;
	}

	.u-menu-wrap {
		flex: 1;
		display: flex;
		overflow: hidden;
	}

	.u-search-inner {
		background-color: rgb(234, 234, 234);
		border-radius: 100rpx;
		display: flex;
		align-items: center;
		padding: 10rpx 16rpx;
	}

	.u-search-text {
		font-size: 26rpx;
		color: $u-tips-color;
		margin-left: 10rpx;
	}

	.u-tab-item {
		height: 110rpx;
		background: #f6f6f6;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 26rpx;
		color: #444;
		font-weight: 400;
		line-height: 1;

		&::-webkit-scrollbar {
			display: none;
		}
	}

	.u-tab-item-active {
		position: relative;
		color: #000;
		font-size: 30rpx;
		font-weight: 600;
		background: #fff;
	}

	// .u-tab-item-active::before {
	// 	content: '';
	// 	position: absolute;
	// 	border-left: 4px solid $u-type-primary;
	// 	height: 32rpx;
	// 	left: 0;
	// 	top: 39rpx;
	// }

	.u-tab-view {
		width: 200rpx;
		height: 100%;

		&::-webkit-scrollbar {
			display: none;
		}
	}

	.right-box {
		background-color: rgb(250, 250, 250);
	}

	.page-view {
		padding: 0;
	}

	.class-item {
		margin-bottom: 30rpx;
		background-color: #fff;
		padding: 16rpx;
		border-radius: 8rpx;
	}

	.item-title {
		font-size: 26rpx;
		color: $u-main-color;
		font-weight: bold;
	}

	.item-menu-name {
		width: 320rpx;
		height: 201rpx;
		display: inline-block;
		vertical-align: top;
		margin-left: 2vw;

		.item-menu-name-title {
			line-height: 3.5vh;
			font-weight: bold;
		}

		.item-menu-name-bq {
			height: 3vh;
			line-height: 3vh;
			font-size: 12px;
		}

		.item-menu-name-ys {
			height: 3vh;
			line-height: 3vh;
			font-size: 12px;
		}

		.item-menu-name-jiage {
			width: 100%;
			height: 4vh;
		}

		.item-menu-name-jg {
			float: left;
			color: red;
			display: inline-block;
			margin-top: 17rpx;
		}

		.item-menu-name-jia {
			float: right;
			width: 20px;
			height: 20px;
			background: #F8F9FA;
			color: #333333;
			display: inline-block;
			text-align: center;
			line-height: 20px;
			border-radius: 50%;
			margin-top: 17rpx;
			margin-left: 20rpx;
			font-size: 12px;
		}
	}

	.item-container {
		display: flex;
		flex-wrap: wrap;
		background: #FFFFFF;
		width: 92%;
		margin: 25rpx auto;
		border-radius: 10px;
	}

	.thumb-box {
		display: block;
		width: 100%;
		margin: 2vh 0;
	}

	.item-menu-image {
		width: 201rpx;
		height: 201rpx;
	}

	.xiadan {
		position: fixed;
		bottom: 10px;
		width: 90%;
		height: 8vh;
		background: #000000;
		border-radius: 40px;
		margin: 0 5%;

		image {
			width: 54px;
			float: left;
			height: 66px;
			margin-top: -46rpx;
			margin-left: 56rpx;
		}

		.xiadanprice {
			display: inline-block;
			color: #fff;
			float: left;
			margin-left: 12rpx;
			line-height: 7vh;
		}

		.xiadanBtn {
			float: right;
			width: 29vw;
			background: #003B40;
			height: 8vh;
			border-bottom-right-radius: 40px;
			border-top-right-radius: 40px;
			color: #fff;
			text-align: center;
			line-height: 8vh;
			font-size: 16px;
		}
	}
</style>